package persistencia;

import org.hibernate.Transaction;
import persistencia.util.HibernateUtil;

public abstract class HibernateDAO <T> {

	public boolean salvar(T obj) {
		Transaction tx = null;
		try {
			tx = HibernateUtil.getSession().beginTransaction();
			HibernateUtil.getSession().saveOrUpdate(obj);
			tx.commit();
		} catch (Exception e) {
			tx.rollback();
		System.out.println(e.getMessage());
		}
		return tx.wasCommitted();
	}
	
	public boolean deletar(T obj) {
		Transaction tx = null;
		try {
			tx = HibernateUtil.getSession().beginTransaction();
			HibernateUtil.getSession().delete(obj);
			tx.commit();

		} catch (Exception e) {
			tx.rollback();
			System.out.println(e.getMessage());
		}
		return tx.wasCommitted();
	}
	
}
